package org.jeecg.modules.deepseek.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pgvector.DefaultMetadataStorageConfig;
import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class chat4jConfig {
    @Bean
    public EmbeddingModel getEmbeddingModel() {
        EmbeddingModel embeddingModel = OpenAiEmbeddingModel.builder()
                .baseUrl("https://api.siliconflow.cn/v1")
//                .proxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress("127.0.0.1", 7890)))
                .apiKey("sk-nrvjihoykgbjabnelziszukgkcankraqcwtvohvpcuepuyyz").modelName("Qwen/Qwen3-Embedding-4B").logRequests(true).logResponses(true).dimensions(2048)
                .build();
        return embeddingModel;
    }

    @Bean
    public EmbeddingStore<TextSegment> embeddingStore(EmbeddingModel embeddingModel){
        log.info("任务启动命令：{}",embeddingModel.dimension());
        return  PgVectorEmbeddingStore.builder()
                .host("localhost")                           // Required: Host of the PostgreSQL instance
                .port(5432)                                  // Required: Port of the PostgreSQL instance
                .database("postgres")                        // Required: Database name
                .user("root")

                .dimension(embeddingModel.dimension())// Required: Database user
                .password("root")
                .useIndex(true)                             // Enable IVFFlat index
                .indexListSize(100) // Required: Database password
                .table("node")
                .metadataStorageConfig(DefaultMetadataStorageConfig.defaultConfig())// Required: Table name to store embeddings
            // Required: Dimension of embeddings
                .build();
    }








}
